﻿using System;

namespace Jasmine.Extensions.Doubles
{

    public static class DoubleExtension
    {
        /// <summary>
        /// Rounds a double-precision floating-point value to a specified number of fractional digits, using midpoint
        /// rounding away from zero.
        /// </summary>
        /// <remarks>This method uses <see cref="MidpointRounding.AwayFromZero"/> to round midpoint
        /// values. If <paramref name="digits"/> is outside the range 0 to 15, an <see
        /// cref="ArgumentOutOfRangeException"/> is thrown.</remarks>
        /// <param name="value">The double-precision floating-point number to round.</param>
        /// <param name="digits">The number of decimal places in the returned value. Must be between 0 and 15, inclusive.</param>
        /// <returns>A double-precision floating-point number rounded to the specified number of fractional digits.</returns>
        public static double ToFixed(this double value, int digits)=> Math.Round(value, digits, MidpointRounding.AwayFromZero);

    }
}
